import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Todo } from '../schema/todo.schema';
import { AddNewTodoDto } from './dto/add-new-todo.dto';

@Injectable()
export class ApiService {
  constructor(@InjectModel(Todo.name) private readonly model: Model<Todo>) {}

  findAllTodos(): Promise<Todo[]> {
    return this.model.find();
  }

  add(dto: AddNewTodoDto): Promise<Todo> {
    return this.model.create(dto);
  }
}
